package com.example;

import java.util.Arrays;

/**
 * 面向对象--封装：
 * 1.将具有共同特征和行为的事物封装成类，JavaBean/实体类
 * 2.将属性隐藏、提供操作属性的方法
 * 编写代码的步骤：
 * 1.定义类和属性（字段），属性必须私有化
 * 2.暴露公开的属性set/get方法，使用自动生成
 * 3.暴露构造方法，如果显式的写出了有参构造方法，必须同时把空参构造方法写出来
 * 4.重写toString()方法
 */
public class User {
    /*  名字、年龄、性别、爱好 */
    private String name;

    private int age;

    private boolean isMan;

    private String[] hobby;

    public User() {

    }

    public User(String name, int age, boolean isMan, String[] hobby) {
        this.name = name;
        setAge(age);
        this.isMan = isMan;
        this.hobby = hobby;
    }

    public User(String name, int age, boolean isMan) {
        this.name = name;
        setAge(age);
        this.isMan = isMan;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        if (age < 0 || age > 150) {
            System.out.println("您输入的年龄有误");
            return;
        }
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public String[] getHobby() {
        return hobby;
    }

    public void setHobby(String[] hobby) {
        this.hobby = hobby;
    }

    public boolean isMan() {
        return isMan;
    }

    public void setMan(boolean man) {
        isMan = man;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", isMan=" + isMan +
                ", hobby=" + Arrays.toString(hobby) +
                '}';
    }
}
